﻿<%@ Page Title="Add Student" Language="C#" MasterPageFile="~/Views/Shared/UserMaster.master"
    Inherits="System.Web.Mvc.ViewPage<Eacademy.Domain.Models.AdminLessonsViewModel>" %>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="/content/js/jquery.tokeninput.js" type="text/javascript"></script>
    <link href="/content/css/token-input.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        $(document).ready(function () {

            $('#Lesson').tinymce(tinyMCEsettings);
            // Multiple files - single input
            var auth = "<% = Request.Cookies[FormsAuthentication.FormsCookieName]==null ? string.Empty : Request.Cookies[FormsAuthentication.FormsCookieName].Value %>";
            var ss = "<%= Session.SessionID %>;"
            $("#multipleFiles").uploadify({
                uploader: "/content/uploadify.swf",
                script: '<%= Url.Action("Upload") %>',
                buttonText: 'Attach Files',
                multi: true,
                fileDataName: 'file',
                sizeLimit: 1048576,
                removeCompleted: false,
                fileDesc: 'Document (*.doc;*.docx;*.txt;*.ppt;*.pdf;*.jpg;*.jpeg;*.png;*.gif)',
                fileExt: '*.doc;*.docx;*.txt;*.ppt;*.pdf;*.jpg;*.jpeg;*.png;*.gif',
                scriptData: { authtoken: auth, si: ss },
                simUploadLimit: 5,
                cancelImg: '/content/images/cancel.png',
                auto: true,
                onError: function (a, b, c, d) {
                    //alert("Error: "+d.type+" Info: "+d.info);
                },
                onComplete: function (event, queueId, fileObj, response, data) {
                    //alert(response.responseText);
                }
            });
            var deleted = [];
            $("#subbtn").click(function () {
                var arr = [];
                arr = $.map($("#multipleFilesQueue .fileName"), function (n, i) {
                    var st = $(n).html();
                    return st.substring(0, st.lastIndexOf(' '));
                });

                $("#savedFiles .fileName").each(function () {
                    arr.push($(this).html());
                });

                $("input[name='filenames']").val(arr.join(","));
                $("input[name='deletefiles']").val(deleted.join(","));
            });
            $(".cancel-exist a").click(function () {
                var $element = $(this);
                $element.parents(".savedFile").toggle("highlight", function () {
                    deleted.push($element.parent().next().html().trim());
                    $element.parents(".savedFile").remove();
                });
                return false;
            });

        });
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit Lesson
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3>
        Add Lesson</h3>
    <% using (Html.BeginForm("Edit", "Lessons", FormMethod.Post, new { autocomplete = "off" }))
       {%>
    <div class="forms-elements">
        <div class="form-wrapper">
            <div class="form-label">
                <%: Html.LabelFor(model => model.Title)%>
            </div>
            <div class="form-element">
                <div class="textbox-xmedium-form">
                    <%: Html.TextBoxFor(model => model.Title, new { @class = "textbox-xmedium-field" })%>
                </div>
            </div>
            <div class="form-error form-error-150">
                <%: Html.ValidationMessageFor(model => model.Title)%>
            </div>
        </div>
        <div class="form-wrapper">
            <div class="form-label">
                <%: Html.LabelFor(model => model.Lesson)%>
            </div>
            <div class="form-element description">
                <%= Html.TextAreaFor(model => model.Lesson)%>
            </div>
            <div class="form-error">
                <%: Html.ValidationMessageFor(model => model.Lesson)%>
            </div>
        </div>
        <div class="form-wrapper">
            <div class="form-label">
            </div>
            <div class="form-element">
                <input type="file" id="multipleFiles" />
                <input type="hidden" name="filenames" value="<%=Model.Files%>" />
                <input type="hidden" name="deletefiles" />
                <div id="savedFiles">
                    <% 
                        if (Model.FileList.Count > 0)
                        {
                            foreach (String filename in Model.FileList)
                            {
                    %>
                    <div class="uploadifyQueueItem completed savedFile">
                        <div class="cancel cancel-exist">
                            <a href="#">
                                <img border="0" src="/content/images/cancel.png"></a>
                        </div>
                        <span class="fileName">
                            <%=filename%></span>
                    </div>
                    <%
                            }
                        }
                    %>
                </div>
            </div>
        </div>
        <div class="form-wrapper">
            <div class="form-label">
            </div>
            <div class="form-element">
                <%: Html.HiddenFor(model => model.SubjectId) %>
                <%: Html.HiddenFor(model => model.LessonId) %>
                <input id="subbtn" type="submit" value="Save" class="button-style" />
            </div>
        </div>
    </div>
    <% } %>
</asp:Content>
